<?php

require_once(sfConfig::get('sf_lib_dir').'/filter/base/BaseFormFilterPropel.class.php');

/**
 * Products filter form base class.
 *
 * @package    tvpv
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormFilterGeneratedTemplate.php 13459 2008-11-28 14:48:12Z fabien $
 */
class BaseProductsFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'reference'         => new sfWidgetFormFilterInput(),
      'code'              => new sfWidgetFormFilterInput(),
      'codetype'          => new sfWidgetFormFilterInput(),
      'name'              => new sfWidgetFormFilterInput(),
      'pricebuy'          => new sfWidgetFormFilterInput(),
      'pricesell'         => new sfWidgetFormFilterInput(),
      'category'          => new sfWidgetFormPropelChoice(array('model' => 'Categories', 'add_empty' => true)),
      'taxcat'            => new sfWidgetFormPropelChoice(array('model' => 'Taxcategories', 'add_empty' => true)),
      'stockcost'         => new sfWidgetFormFilterInput(),
      'stockvolume'       => new sfWidgetFormFilterInput(),
      'image'             => new sfWidgetFormFilterInput(),
      'iscom'             => new sfWidgetFormFilterInput(),
      'isscale'           => new sfWidgetFormFilterInput(),
      'attributes'        => new sfWidgetFormFilterInput(),
      'stockcurrent_list' => new sfWidgetFormPropelChoice(array('model' => 'Locations', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'reference'         => new sfValidatorPass(array('required' => false)),
      'code'              => new sfValidatorPass(array('required' => false)),
      'codetype'          => new sfValidatorPass(array('required' => false)),
      'name'              => new sfValidatorPass(array('required' => false)),
      'pricebuy'          => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'pricesell'         => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'category'          => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Categories', 'column' => 'id')),
      'taxcat'            => new sfValidatorPropelChoice(array('required' => false, 'model' => 'Taxcategories', 'column' => 'id')),
      'stockcost'         => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'stockvolume'       => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'image'             => new sfValidatorPass(array('required' => false)),
      'iscom'             => new sfValidatorPass(array('required' => false)),
      'isscale'           => new sfValidatorPass(array('required' => false)),
      'attributes'        => new sfValidatorPass(array('required' => false)),
      'stockcurrent_list' => new sfValidatorPropelChoice(array('model' => 'Locations', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('products_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addStockcurrentListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(StockcurrentPeer::PRODUCT, ProductsPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(StockcurrentPeer::LOCATION, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(StockcurrentPeer::LOCATION, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'Products';
  }

  public function getFields()
  {
    return array(
      'id'                => 'Text',
      'reference'         => 'Text',
      'code'              => 'Text',
      'codetype'          => 'Text',
      'name'              => 'Text',
      'pricebuy'          => 'Number',
      'pricesell'         => 'Number',
      'category'          => 'ForeignKey',
      'taxcat'            => 'ForeignKey',
      'stockcost'         => 'Number',
      'stockvolume'       => 'Number',
      'image'             => 'Text',
      'iscom'             => 'Text',
      'isscale'           => 'Text',
      'attributes'        => 'Text',
      'stockcurrent_list' => 'ManyKey',
    );
  }
}
